package data

import (
	"lnzw/engine/aoi/crosslinks"
	"sync/atomic"
	"time"
)

type UnitType int

const (
	Player  UnitType = iota
	Monster UnitType = iota
	NPC     UnitType = iota
	Item    UnitType = iota
)

type IUnit interface {
	crosslinks.Entity
	GetUnitType() UnitType
	GetUnitId() int64
	GetPosition() crosslinks.Point
	OnEnterMap(*Map)
	GetViewRange() int
}

type BaseUnit struct {
	crosslinks.AOIEntity
	Id        int64
	NowMap    *Map
	ViewRange int
}

var id int64 = time.Now().UnixNano()

func GenUnitId() int64 {
	return atomic.AddInt64(&id, 1)
}

func (b *BaseUnit) GetUnitId() int64 {
	return b.Id
}

func (b *BaseUnit) GetUnitType() UnitType {
	panic("implement me")
}

func (b *BaseUnit) GetPosition() crosslinks.Point {
	return b.Pos
}

func (b *BaseUnit) OnEnterMap(m *Map) {
	b.NowMap = m
}

func (b *BaseUnit) GetViewRange() int {
	return b.ViewRange
}
